<template>
  <div>
    <el-card class="box-card">
      <div class="allDiv">
        <div>配置名字</div>
        <div>备注</div>
        <div>操作</div>
      </div>
    </el-card>
    <el-card class="box-card">
      <div class="allDiv">
        <div>{{ tableData.name }}</div>
        <div>{{ tableData.remark }}</div>
        <div>
          <el-switch
            v-model="tableData.value"
            active-text="是"
            inactive-text="否"
            @change="rowUpdate"
            style="width: 30%; margin-left: 42%"
          >
          </el-switch>
        </div>
      </div>
    </el-card>
    <el-card class="box-card">
      <div class="allDiv">
        <div>生成奖学金静态数据</div>
        <div>我是备注备注备注</div>
        <div>
          <el-button
            type="primary"
            v-show="getPermissions('staticData_create')"
            style="margin-left: 2.5%"
            @click="generateData"
            >生成</el-button
          >
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import {
  updateGlobeConfig,
  searchGlobeConfig,
  staticData,
} from "@/api/permission/globalSettings";
export default {
  name: "",
  data() {
    return {
      tableData: [],
      name: "是否数据维护",
    };
  },
  created() {
    this.searchHandler();
  },
  methods: {
    getPermissions(value) {
      return this.getPermission(value);
    },
    generateData() {
      this.$confirm(
        "是否确保所有班级数据录入已完成并且已分配奖学金名额，如有原有数据，则会覆盖，是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          staticData().then((res) => {
            console.log(res);
            this.$message.success(res.data);
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    searchHandler() {
      searchGlobeConfig(this.name).then((res) => {
        if (res.data.value == "是") {
          res.data.value = true;
        } else {
          res.data.value = false;
        }
        this.tableData = res.data;
      });
    },
    rowUpdate() {
      if (this.tableData.value == true) {
        this.tableData.value = "是";
      } else {
        this.tableData.value = "否";
      }
      const obj = {
        id: this.tableData.id,
        remark: this.tableData.remark,
        value: this.tableData.value,
      };
      console.log(obj);
      updateGlobeConfig(obj).then(() => {
        this.$message.success("更新成功");
        this.searchHandler();
      });
    },
  },
};
</script>


<style>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:after {
  clear: both;
  border: 1px solid;
}

.clearfix {
  height: 40px;
}

.box-card {
  width: 95%;
  margin: 10px auto;
  padding: 5px;
}

.allDiv div {
  width: 33%;
  float: left;
  text-align: center;
  margin-bottom: 20px;
}
</style>